package pa165.dominatingspecies.service.converter;

import java.util.ArrayList;
import java.util.List;
import pa165.dominating.species.entities.Environment;
import pa165.dominating.species.tos.EnvironmentTo;

/**
 *
 * @author Filip Dinh
 */
public class EnvironmentConverter {

    private ElementConverter elementConverter = new ElementConverter();

    public Environment convertEnvironmentTo2Environment(EnvironmentTo environmentTo) {
        Environment environment = new Environment();
        environment.setId(environmentTo.getId());
        environment.setDescription(environmentTo.getDescription());
        environment.setName(environmentTo.getName());
        environment.setElements(elementConverter.convert2Element(environmentTo.getElements()));
        return environment;
    }

    public EnvironmentTo convertEnvironment2EnvironmentTo(Environment environment) {
        EnvironmentTo environmentTo = new EnvironmentTo();
        environmentTo.setId(environment.getId());
        environmentTo.setName(environment.getName());
        environmentTo.setDescription(environment.getDescription());
        environmentTo.setElements(elementConverter.convert2ElementTo(environment.getElements()));
        return environmentTo;
    }

    public List<EnvironmentTo> convert2EnvironmentTo(List<Environment> environments) {
        final List<EnvironmentTo> environmentTos = new ArrayList<>();
        for (Environment environment : environments) {
            environmentTos.add(convertEnvironment2EnvironmentTo(environment));
        }
        return environmentTos;
    }

    public List<Environment> convert2Environment(List<EnvironmentTo> environmentTos) {
        final List<Environment> environments = new ArrayList<>();
        for (EnvironmentTo environmentTo : environmentTos) {
            environments.add(convertEnvironmentTo2Environment(environmentTo));
        }
        return environments;
    }
}
